use super::*;

#[derive(Debug, Default, Clone)]
pub struct MetaInfo {
	pub creator: String,
	pub format_version: u64,
	pub format_version_minor: u64,
}

impl FromPlist for MetaInfo {
	fn from_plist(r: &mut Parser<'_, '_, '_>) -> Result<Self, Error> {
		r.dict_start()?;
		let mut this = Self::default();
		loop {
			match r.next()? {
				plist::Event::End => break,
				plist::Event::Error(e, _) => return Err(Error::Plist(e)),
				plist::Event::Key(key) => match key {
					"creator" => this.creator = r.string()?,
					"formatVersion" => this.format_version = r.uinteger()?,
					"formatVersionMinor" => this.format_version_minor = r.uinteger()?,
					_ => r.skip_value()?,
				},
				_ => return Err(Error::Msg("expect key")),
			}
		}
		Ok(this)
	}
}
